<?php
/**
 * 专题
 */
class Controller_App_Topic extends Controller_App_Template
{
    public function __construct ($req, $res)
    {
        $this->template = "smarty:app/topic_list";
        parent::__construct($req, $res);
    }

    public function action_index ()
    {
        //
        $this->action_list(1);
        $title_json  = App_Util::buildClientTitleJson('back', 'block', '专题', 'message', 'none', '');
        $bottom_json = App_Util::buildClientBottomJson('none', 'homepage');
        
        $this->template->set('title_json',   $title_json);
        $this->template->set('bottom_json',  $bottom_json);
    }

    // 专题列表
    public function action_list ($page = 1)
    {
        $page  = max(1, $page);
        $limit = 10;
        $start = ($page - 1) * $limit;

        $topic     = new App_Topic();
        $topicList = $topic->topics($start, $limit);
        $this->template->set('topics', $topicList);
        $this->template->set('title', '全部专题');
    }

    // 专题详情
    public function action_detail ($nid = 1)
    {
        //
        $detail = App_Topic::detail($nid);
        $this->template->set('topic', $detail);
        $this->template->set('title', $detail['title']);
        $this->template->set('goodsItems', Arr::get($detail, 'goodsList'));
        $this->template->set('shareTitle', App_Util::buildShareContent($detail['title']));
        $this->template->set('shareDesc', App_Util::buildShareContent($detail['shortDesc']));
        $this->template->set_filename("smarty:app/topic_detail");
        
        $title_json  = App_Util::buildClientTitleJson('back', 'block', '专题', 'share', 'block', '');
        $bottom_json = App_Util::buildClientBottomJson('none', 'homepage');
        
        $this->template->set('title_json',   $title_json);
        $this->template->set('bottom_json',  $bottom_json);
    }

    // 最新商品
    public function action_newest ()
    {
        $detail = App_Topic::newest();
        $this->template->set('topic', $detail);
        $this->template->set('title', $detail['title']);
        $this->template->set('goodsItems', Arr::get($detail, 'goodsList'));
        $this->template->set_filename("smarty:app/topic_detail");
    }
}
